window.addEventListener('DOMContentLoaded', function() {
    var videoPlayer = document.getElementById('video-player');
    var progressBar = document.getElementById('progress');
    var timeDisplay = document.getElementById('time-display');

    videoPlayer.addEventListener('loadedmetadata', function() {
        var durationMinutes = Math.floor(videoPlayer.duration / 60);
        var durationSeconds = Math.floor(videoPlayer.duration - durationMinutes * 60);

        if (durationSeconds < 10) {
            durationSeconds = "0" + durationSeconds;
        }

        timeDisplay.textContent = "0:00 / " + durationMinutes + ":" + durationSeconds;

        videoPlayer.style.display = "block"; // 显示视频元素
    });

    videoPlayer.addEventListener('timeupdate', function() {
        var progress = (videoPlayer.currentTime / videoPlayer.duration) * 100;
        progressBar.style.width = progress + '%';

        var currentMinutes = Math.floor(videoPlayer.currentTime / 60);
        var currentSeconds = Math.floor(videoPlayer.currentTime - currentMinutes * 60);

        if (currentSeconds < 10) {
            currentSeconds = "0" + currentSeconds;
        }

        timeDisplay.textContent = currentMinutes + ":" + currentSeconds + " / " + timeDisplay.textContent.split(" / ")[1];
    });

    videoPlayer.addEventListener('play', function() {
        console.log('视频开始播放');
    });

    videoPlayer.addEventListener('pause', function() {
        console.log('视频已暂停');
    });

    videoPlayer.addEventListener('ended', function() {
        console.log('视频播放结束');
    });
});